package com.petlab.action.thread;

import java.util.HashMap;
import java.util.Map;
import javaMail.VelocityEmailService;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import com.petlab.model.Register;

@Component("regEmailThread")
@Scope("prototype")
public class RegEmailThread extends Thread{
	
	private Register register;
	
	
	public Register getRegister() {
		return register;
	}
	public void setRegister(Register register) {
		this.register = register;
	}
	
	public void run() {
		// TODO Auto-generated method stub
		ApplicationContext context = new ClassPathXmlApplicationContext(
		"javaMail/VelocityEmailConfig.xml");

		VelocityEmailService tves = context
			.getBean(VelocityEmailService.class);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("userName", this.getRegister().getRealName());
		model.put("emailAddress", this.getRegister().getEmail());


		tves.sendEmail(model, "Welcome join us!", "javaMail/Welcome.vm",
		new String[] { this.getRegister().getEmail()}, new String[] {
				});
	}
}
